var  flag=false;
var vm=new Vue({
        el:"#form",
        data:{
            imageUrl:"http://"+document.domain+"/Captcha.jpg",
            username:'',
            password:'',
            captcha:'',
            rememberMe:flag,
            error_message:'',
            activeColor:'',
            userInfo:{},
            flag_alert:"",
            error_message:'',
            index:0
        },
        mouted:function(){
            this.getCapture()
        },
        methods:{
            getCapture:function(){
                console.log("点击事件")
                vm.imageUrl="http://"+document.domain+"/Captcha.jpg?" + new Date().getTime();
            },

            check:function(){
                if (flag==false){
                    flag=true
                    vm.rememberMe=flag
                    vm.activeColor='red'
                    console.log(vm.rememberMe)
                    vm.flag_alert="您选择了记住密码"
                    return
                }
                if (flag==true){
                    flag=false
                    vm.rememberMe=flag
                    vm.activeColor=''
                    console.log(vm.rememberMe)
                    vm.flag_alert="您选择了不记住密码，两小时得重新登陆"
                }
            },

            login:function () {
                // var url = window.location.protocol+&quot
                console.log("登陆成功")
                console.log(flag)
                vm.awaitlogin().then(function (res) {
                    console.log(res)
                    var state=res.status
                    var code=res.data.code
                    // if (state==200){
                    //     if (code==100){
                    //         window.location="../index"
                    //     }
                    // } else {
                    //     alert("登陆失败")
                    // }
                    console.log(res.data);
                    if (res.data.code==700){
                        vm.error_message=res.data.msg
                    }
                    if (res.data.code==100) {
                        window.location.href="../index"
                        vm.error_message=res.data.msg
                    }
                    if (res.data.code==101){
                        window.location.href="../index"
                        vm.error_message=res.data.msg
                    }
                })
            },

            awaitlogin:function () {
                return new Promise(function (resolve,reject){
                    axios({
                        method:'get',
                        url:'../login?'+"username="+vm.username+"&"+"password="+vm.password+"&"+"captcha="+vm.captcha+"&"+"rememberMe="+vm.rememberMe,
                    }).then(function (res) {
                        resolve(res)
                    }).catch(function (res) {
                        reject(res)
                    })
                })
            }
        }
    })



